<?php

/**
 * This is the model class for table "tbl_homework".
 *
 * The followings are the available columns in table 'tbl_homework':
 * @property integer $homework_id
 * @property string $student_id
 * @property string $date_created
 * @property string $homework_content
 * @property string $teacher_commment
 * @property string $grade
 */
class Homework extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Homework the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_homework';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('student_id, date_created', 'required'),
			array('student_id, grade', 'length', 'max'=>128),
			array('homework_content, teacher_commment', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('homework_id, student_id, date_created, homework_content, teacher_commment, grade', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'homework_id' => 'Homework',
			'student_id' => 'Student',
			'date_created' => 'Date Created',
			'homework_content' => 'Homework Content',
			'teacher_commment' => 'Teacher Commment',
			'grade' => 'Grade',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('homework_id',$this->homework_id);
		$criteria->compare('student_id',$this->student_id,true);
		$criteria->compare('date_created',$this->date_created,true);
		$criteria->compare('homework_content',$this->homework_content,true);
		$criteria->compare('teacher_commment',$this->teacher_commment,true);
		$criteria->compare('grade',$this->grade,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}